import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../pages/station/station_equip_edit.dart';
import '../../helper/routeHelper.dart';
import '../../model/station.dart';
import '../../model/stationequip.dart';
import '../../widgets/inputWidget.dart';
import '../../helper/Helper.dart';
import '../../helper/uidata.dart';
import '../../widgets/IconWidget.dart';
import 'station_helper.dart';

class StationEquipInfoPage extends StatefulWidget {
  @override
  StationEquipInfoPage(this.e1, this.s1, this.callback);
  final StationEquip e1;
  final Station s1;
  final RefrushCallback callback;

  @override
  createState() => new StationEquipInfoPageState();
}

class StationEquipInfoPageState extends State<StationEquipInfoPage> {
  late StationEquip e1;
  final TextEditingController c2 = new TextEditingController();

  @override
  void initState() {
    super.initState();
    //s1 = widget.s1;
    //UIData.CurrentUser!.Authority="水调值班员,电厂值班员";
    loadData();
  }

  loadData() async {
    var s2 = await StationEquip.Get("ID=@ID", {"ID": widget.e1.ID});
    setState(() {
      e1 = s2!;
    });
  }

  List<Widget> getAllWidget(BuildContext context) {
    List<Widget> list1 = <Widget>[];
    List<Widget> list2 = <Widget>[];
    List<Widget> list3 = <Widget>[];

    list1.add(InputWidget.inCard(
      ListTile(
        leading: IconWidget.RiverImage(),
        title: Text("设备详情"),
      ),
    ));

    list2.add(InputWidget.getInfo("设备名称", e1.Name));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo("设备状态", e1.EState));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo("设备型号", e1.Model));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo("生产厂家", e1.FacturerName));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo("生产日期", e1.FactureTime));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInfo2("备注", e1.Remark));
    list1.add(InputWidget.inCard2(list2));

    //list1.add(InputWidget.getQMTile(s1.State==6, Helper.DateTimeFormat(s1.HZQMTM), s1.HZQM));
    return list1;
  }

  Widget getFloatingButton(BuildContext context) {
    if (StationHelper.IfGuanLi(UIData.CurrentUser!)) {
      return FloatingActionButton(
          child: Icon(FontAwesomeIcons.penAlt),
          onPressed: () => RouteHelper.ShowPage(context,
              StationEquipAddPage(widget.e1, widget.s1, widget.callback)));
    }

    return new Container();
  }

  @override
  Widget build(BuildContext context) {
    // if (s1 == null) return Center(child:SpinKitCircle(color: Colors.blue,));

    // TODO: implement build
    return Scaffold(
        appBar: AppBar(title: Text(widget.s1.STNM)),
        //bottomSheet:bottomPanel2() ,
        floatingActionButton: getFloatingButton(context),
        body: e1 == null
            ? Center(
                child: SpinKitCircle(
                color: Colors.blue,
              ))
            : SingleChildScrollView(
                child: new Container(
                    margin: EdgeInsets.only(top: 4.0),
                    child: new Column(children: getAllWidget(context))),
              ));
  }
}
